package com.gerfmarquez.nymph.db.sqlite;

import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class NoteLengthDbAdapter {
	
	
	private SQLiteDatabase database;
	
	private final String  KEY_NOTE_LENGTH = "id_note_length";
	private final String  KEY_LENGTH_NAME = "length_nick";
	private final String  KEY_LENGTH_DESCRIPTION = "length_description";
	
	private final String NOTE_LENGTH_TABLE = "note_length";
	
	
	public NoteLengthDbAdapter(SQLiteDatabase database) {
		this.database = database;
	}
	public int getNoteLengthId(int lengthNameInt) throws SQLException {
		Cursor mCursor = database.query(true, NOTE_LENGTH_TABLE, new String[] {
				KEY_NOTE_LENGTH, KEY_LENGTH_NAME, KEY_LENGTH_DESCRIPTION },
				KEY_LENGTH_NAME + "=" + lengthNameInt, null, null, null, null, null);
		if (mCursor != null) {
			mCursor.moveToFirst();
			return mCursor.getInt(mCursor.getColumnIndex(KEY_NOTE_LENGTH));
		}
		return 0;
	}
	public int getNoteLengthFromId(int lengthId) throws SQLException {
		Cursor mCursor = database.query(true, NOTE_LENGTH_TABLE, new String[] {
				KEY_NOTE_LENGTH, KEY_LENGTH_NAME, KEY_LENGTH_DESCRIPTION },
				KEY_NOTE_LENGTH + "=" + lengthId, null, null, null, null, null);
		if (mCursor != null) {
			mCursor.moveToFirst();
			if(!mCursor.isAfterLast()) {
				return mCursor.getInt(mCursor.getColumnIndex(KEY_LENGTH_NAME));
			}
		}
		return 0;
	}
	
}
